package com.myzl.coal.mq;


import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static com.myzl.coal.mq.MqConstant.*;
/**
 * @ClassName FanoutRabbitConfig
 * @Author wzb
 * @Date 2022/7/12 14:22
 * @Description
 */
@Configuration
public class FanoutRabbitConfig {


    @Value("${spring.application.name}")
    public  String PROJECT_NAME ;


    /******************************************************报警**********************************************/
    @Bean
    public Queue policeStorage() {
        return new Queue(PROJECT_NAME+SPIT+POLICE );
    }

    @Bean
    FanoutExchange policeFanoutExchange() {
        return new FanoutExchange(POLICE_FANOUT_EXCHANGE);
    }

    @Bean
    Binding bindingExchangePolice() {
        return BindingBuilder.bind(policeStorage()).to(policeFanoutExchange());
    }
    /******************************************************恢复**********************************************/
    @Bean
    public Queue restore() {
        return new Queue(PROJECT_NAME+SPIT+RESTORE );
    }

    @Bean
    FanoutExchange restoreFanoutExchange() {
        return new FanoutExchange(RESTORE_FANOUT_EXCHANGE);
    }

    @Bean
    Binding bindingExchangeRestore() {
        return BindingBuilder.bind(restore()).to(restoreFanoutExchange());
    }

    /******************************************************实时**********************************************/
    @Bean
    public Queue realtimeDataStorage() {
        return new Queue(PROJECT_NAME+SPIT+REAL_TIME_DATA );
    }

    @Bean
    FanoutExchange realtimeDataFanoutExchange() {
        return new FanoutExchange(REAL_TIME_DATA_FANOUT_EXCHANGE);
    }

    @Bean
    Binding bindingExchangeRealtimeData() {
        return BindingBuilder.bind(realtimeDataStorage()).to(realtimeDataFanoutExchange());
    }

    /******************************************************状态**********************************************/
    @Bean
    public Queue deviceStatus() {
        return new Queue(PROJECT_NAME+SPIT+DEVICE_STATUS );
    }

    @Bean
    FanoutExchange deviceStatusFanoutExchange() {
        return new FanoutExchange(FANOUT_EXCHANGE_DEVICE_STATUS);
    }

    @Bean
    Binding bindingExchangeDeviceStatus() {
        return BindingBuilder.bind(deviceStatus()).to(deviceStatusFanoutExchange());
    }

    @Bean
    public MessageConverter messageConverter() {
        return new Jackson2JsonMessageConverter();
    }


}
